﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class clsUpdate
{
    private static String comments;
    private static List<String> listStpUpdates;
    private static List<String> listUpdateVersions = new List<string> 
        {
            "v1001"//, "v1002", "v1003", "v1004", "v1005", "v1006" 
        };
    private static string query;
    private static System.Data.SqlClient.SqlDataReader rd;
    public static void UpdateDatabase()
    {
        try
        {
            query = @"Select UpdateVersion from StpUpdate";
            rd = ConnectionManager.ExecuteReader(query);
            listStpUpdates = clsMethods.ConvertToList<String>(rd, 0);
            foreach (var update in listUpdateVersions)
            {
                if (!listStpUpdates.Contains(update))
                {
                    StartUpdate(update);
                    InsertIntoStpUpdate(update, comments);
                    comments = null;
                }
            }
            //foreach (var update in listUpdateVersions)
            //{
            //    if (!listStpUpdates.Contains(update))
            //    {
            //        StartUpdate(update);
            //        InsertIntoStpUpdate(update, comments);
            //        comments = null;
            //    }
            //}
        }
        catch (Exception ex)
        {
        }
    }

    private static void InsertIntoStpUpdate(string update, string comments)
    {
        query = @"INSERT INTO [dbo].[StpUpdate]
                           ([UpdateVersion]
                           ,[Date]
                           ,[Comments])
                     VALUES
                           ('" + update + "','" + DateTime.Today.Date + "','" + comments + "')";
        ConnectionManager.ExecuteQueries(query);
    }

    private static void StartUpdate(string update)
    {

        switch (update)
        {
            case "v1001":
                updateV1001();
                comments = "First update of the WebsitePractice.";
                break;

            //case "v1002":
            //    break;

            //case "v1003":
            //    break;

            //case "v1004":
            //    break;

            //case "v1005":
            //    break;

            //case "v1006":
            //    break;

            //case "v1007":
            //    break;

            default:
                break;
        }

    }

    private static void updateV1001()
    {

    }
}
